﻿<Application 
    x:Class="SliderApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:local="clr-namespace:SliderApp" xmlns:Controls="clr-namespace:Blacklight.Controls">

    <!--Application Resources-->
    <Application.Resources>

        <ControlTemplate x:Key="PhoneSimpleRepeatButton" TargetType="RepeatButton">
            <Rectangle/>
        </ControlTemplate>

        <ControlTemplate x:Key="PhoneSimpleThumbHorizontal" TargetType="Thumb">
            <Border Background="Transparent" Margin="-480,-18">
                <Rectangle Width="2" Height="6" Fill="{StaticResource PhoneForegroundBrush}"/>
            </Border>
        </ControlTemplate>

        <ControlTemplate x:Key="PhoneSimpleThumbVertical" TargetType="Thumb">
            <Border Background="Transparent" Margin="-6,-800">
                <Rectangle Width="6" Height="2" Margin="24,0,0,0" Fill="{StaticResource PhoneForegroundBrush}"/>
            </Border>
        </ControlTemplate>

        <Style x:Key="sliderStyle" TargetType="local:PhoneSlider">
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Maximum" Value="10"/>
            <Setter Property="Minimum" Value="0"/>
            <Setter Property="Value" Value="0"/>
            <Setter Property="Margin" Value="{StaticResource PhoneHorizontalMargin}"/>
            <Setter Property="Background" Value="{StaticResource PhoneContrastBackgroundBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:PhoneSlider">
                        <Grid Background="Transparent">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="HorizontalTrack" Storyboard.TargetProperty="Opacity" To="0.1" />
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="VerticalTrack" Storyboard.TargetProperty="Opacity" To="0.1" />
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalFill" Storyboard.TargetProperty="Fill">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="VerticalFill" Storyboard.TargetProperty="Fill">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="HorizontalTemplate">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="0"/>
                                    <ColumnDefinition Width="auto"/>
                                </Grid.ColumnDefinitions>
                                <Rectangle x:Name="HorizontalTrack" IsHitTestVisible="False" Fill="{TemplateBinding Background}" Opacity="0.2" Grid.ColumnSpan="3" Height="12" Margin="0,22,0,50"/>
                                <Rectangle x:Name="HorizontalFill" IsHitTestVisible="False" Fill="{TemplateBinding Foreground}" Grid.Column="0" Height="12" Margin="0,22,0,50"/>
                                <RepeatButton x:Name="HorizontalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource PhoneSimpleRepeatButton}" Grid.Column="0" />
                                <RepeatButton x:Name="HorizontalTrackLargeChangeIncreaseRepeatButton" IsTabStop="False" Template="{StaticResource PhoneSimpleRepeatButton}" Grid.Column="2" />
                                <Thumb x:Name="HorizontalThumb" Width="1" Margin="-1,0,0,0" Grid.Column="1" Template="{StaticResource PhoneSimpleThumbHorizontal}" RenderTransformOrigin="0.5,0.5" CacheMode="BitmapCache"/>
                            </Grid>
                            <Grid x:Name="VerticalTemplate">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="0"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Rectangle x:Name="VerticalTrack" IsHitTestVisible="False" Fill="{TemplateBinding Background}" Opacity="0.2" Grid.RowSpan="3" Width="12" Margin="24,0"/>
                                <Rectangle x:Name="VerticalFill" IsHitTestVisible="False" Fill="{TemplateBinding Foreground}" Grid.Row="2" Width="12" Margin="24,0"/>
                                <RepeatButton x:Name="VerticalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource PhoneSimpleRepeatButton}" Grid.Row="0"/>
                                <RepeatButton x:Name="VerticalTrackLargeChangeIncreaseRepeatButton" IsTabStop="False" Template="{StaticResource PhoneSimpleRepeatButton}" Grid.Row="2"/>
                                <Thumb x:Name="VerticalThumb" Height="1" Margin="0,-1,0,0" Grid.Row="1" Template="{StaticResource PhoneSimpleThumbVertical}" RenderTransformOrigin="0.5,0.5" CacheMode="BitmapCache"/>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- RANGE SLIDER -->
        <Style x:Key="RangeSliderStyle" TargetType="Controls:RangeSlider">
            <Setter Property="BorderThickness"
                    Value="1" />
            <Setter Property="BorderBrush"
                    Value="Black" />
            <Setter Property="Background"
                    Value="#7fffffff" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Controls:RangeSlider">
                        <Border Padding="{TemplateBinding Padding}">
                            <Grid>
                                <Rectangle Height="2"
                                           Fill="Black"
                                           VerticalAlignment="Center"
                                           Margin="2.5,0,2.5,0" />
                                <Border x:Name="SelectedRangeBorder"
                                        Margin="0">
                                    <Grid>
                                        <Grid.Resources>
                                            <Style x:Key="EndThumbStyle"
                                                   TargetType="Thumb">
                                                <Setter Property="Background"
                                                        Value="#FF1F3B53" />
                                                <Setter Property="BorderThickness"
                                                        Value="1" />
                                                <Setter Property="IsTabStop"
                                                        Value="False" />
                                                <Setter Property="BorderBrush">
                                                    <Setter.Value>
                                                        <LinearGradientBrush EndPoint="0.5,1"
                                                                             StartPoint="0.5,0">
                                                            <GradientStop Color="#FFA3AEB9"
                                                                          Offset="0" />
                                                            <GradientStop Color="#FF8399A9"
                                                                          Offset="0.375" />
                                                            <GradientStop Color="#FF718597"
                                                                          Offset="0.375" />
                                                            <GradientStop Color="#FF617584"
                                                                          Offset="1" />
                                                        </LinearGradientBrush>
                                                    </Setter.Value>
                                                </Setter>
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="Thumb">
                                                            <Grid Background="Transparent">
                                                                <VisualStateManager.VisualStateGroups>
                                                                    <VisualStateGroup x:Name="CommonStates">
                                                                        <VisualState x:Name="Normal" />
                                                                        <VisualState x:Name="MouseOver">
                                                                            <Storyboard>
                                                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation"
                                                                                                               Storyboard.TargetProperty="Opacity">
                                                                                    <SplineDoubleKeyFrame KeyTime="0"
                                                                                                          Value="1" />
                                                                                </DoubleAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#F2FFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#CCFFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#7FFFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                            </Storyboard>
                                                                        </VisualState>
                                                                        <VisualState x:Name="Pressed">
                                                                            <Storyboard>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                                                              Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#FF6DBDD1" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation"
                                                                                                               Storyboard.TargetProperty="Opacity">
                                                                                    <SplineDoubleKeyFrame KeyTime="0"
                                                                                                          Value="1" />
                                                                                </DoubleAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#D8FFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#C6FFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#8CFFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient"
                                                                                                              Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
                                                                                    <SplineColorKeyFrame KeyTime="0"
                                                                                                         Value="#3FFFFFFF" />
                                                                                </ColorAnimationUsingKeyFrames>
                                                                            </Storyboard>
                                                                        </VisualState>
                                                                        <VisualState x:Name="Disabled">
                                                                            <Storyboard>
                                                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualElement"
                                                                                                               Storyboard.TargetProperty="Opacity">
                                                                                    <SplineDoubleKeyFrame KeyTime="0"
                                                                                                          Value=".55" />
                                                                                </DoubleAnimationUsingKeyFrames>
                                                                            </Storyboard>
                                                                        </VisualState>
                                                                    </VisualStateGroup>
                                                                    <VisualStateGroup x:Name="FocusStates">
                                                                        <VisualState x:Name="Focused">
                                                                            <Storyboard>
                                                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement"
                                                                                                               Storyboard.TargetProperty="Opacity">
                                                                                    <SplineDoubleKeyFrame KeyTime="0"
                                                                                                          Value="1" />
                                                                                </DoubleAnimationUsingKeyFrames>
                                                                            </Storyboard>
                                                                        </VisualState>
                                                                        <VisualState x:Name="Unfocused" />
                                                                    </VisualStateGroup>
                                                                </VisualStateManager.VisualStateGroups>
                                                                <Border x:Name="Background"
                                                                        Background="White"
                                                                        BorderBrush="{TemplateBinding BorderBrush}"
                                                                        BorderThickness="{TemplateBinding BorderThickness}"
                                                                        CornerRadius="2"
                                                                        Margin="0,5">
                                                                    <Grid Margin="1"
                                                                          Background="{TemplateBinding Background}">
                                                                        <Border x:Name="BackgroundAnimation"
                                                                                Opacity="0"
                                                                                Background="#FF448DCA" />
                                                                        <Rectangle x:Name="BackgroundGradient">
                                                                            <Rectangle.Fill>
                                                                                <LinearGradientBrush EndPoint=".7,1"
                                                                                                     StartPoint=".7,0">
                                                                                    <GradientStop Color="#FFFFFFFF"
                                                                                                  Offset="0" />
                                                                                    <GradientStop Color="#F9FFFFFF"
                                                                                                  Offset="0.375" />
                                                                                    <GradientStop Color="#E5FFFFFF"
                                                                                                  Offset="0.625" />
                                                                                    <GradientStop Color="#C6FFFFFF"
                                                                                                  Offset="1" />
                                                                                </LinearGradientBrush>
                                                                            </Rectangle.Fill>
                                                                        </Rectangle>
                                                                    </Grid>
                                                                </Border>
                                                                <Rectangle x:Name="DisabledVisualElement"
                                                                           Fill="#FFFFFFFF"
                                                                           RadiusX="2"
                                                                           RadiusY="2"
                                                                           IsHitTestVisible="false"
                                                                           Opacity="0"
                                                                           Margin="0,15" />
                                                                <Rectangle x:Name="FocusVisualElement"
                                                                           Stroke="#FF6DBDD1"
                                                                           StrokeThickness="1"
                                                                           RadiusX="1"
                                                                           RadiusY="1"
                                                                           Margin="1,6"
                                                                           IsHitTestVisible="false"
                                                                           Opacity="0" />
                                                                <StackPanel HorizontalAlignment="Center"
                                                                            Orientation="Horizontal"
                                                                            Margin="0,8"
                                                                            MaxHeight="10">
                                                                    <Rectangle Width="1"
                                                                               Fill="Black" />
                                                                    <Rectangle Fill="Black"
                                                                               Width="1"
                                                                               Margin="1,0,0,0" />
                                                                </StackPanel>
                                                            </Grid>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </Grid.Resources>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <Thumb x:Name="RangeCenterThumb"
                                               Grid.Column="1"
                                               Cursor="Hand"
                                               Margin="-5,0,-5,0"
                                               BorderBrush="{TemplateBinding BorderBrush}"
                                               BorderThickness="{TemplateBinding BorderThickness}"
                                               Background="{TemplateBinding Background}">
                                            <Thumb.Style>
                                                <Style TargetType="Thumb">
                                                    <Setter Property="Template">
                                                        <Setter.Value>
                                                            <ControlTemplate TargetType="Thumb">
                                                                <Grid Background="Transparent">
                                                                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                                                                            BorderThickness="{TemplateBinding BorderThickness}"
                                                                            Background="{TemplateBinding Background}"
                                                                            CornerRadius="3" />
                                                                </Grid>
                                                            </ControlTemplate>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </Thumb.Style>
                                        </Thumb>

                                        <Thumb x:Name="RangeStartThumb"
                                               Cursor="SizeWE"
                                               Width="10"
                                               Style="{StaticResource EndThumbStyle}"
                                               BorderBrush="{TemplateBinding BorderBrush}"
                                               BorderThickness="{TemplateBinding BorderThickness}" />

                                        <Thumb x:Name="RangeEndThumb"
                                               Grid.Column="2"
                                               Cursor="SizeWE"
                                               Width="10"
                                               Style="{StaticResource EndThumbStyle}"
                                               BorderBrush="{TemplateBinding BorderBrush}"
                                               BorderThickness="{TemplateBinding BorderThickness}" />

                                    </Grid>
                                </Border>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService 
            Launching="Application_Launching" Closing="Application_Closing" 
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>